import { createRouter, createWebHashHistory } from 'vue-router';
import { getUrlKey } from '@/util/index.js';
import { Storage } from '@/util/storage';
// import mineRouter from "./mineRouter";
// import JsBridge from "../utils/jsbridge";
// const routerHistory = createWebHistory();

const routes = [
  // route -> routes
  // 首页
  {
    path: '/',
    redirect: '/main',
  },
  // 编辑器页面
  {
    path: '/main',
    name: 'main',
    component: () => import('../views/main.vue'),
  },
  {
    path: '/TemplateLists',
    name: 'TemplateLists',
    component: () => import('../views/svgModel/templateLists.vue'),
  },
  // 预览页页面
  {
    path: '/CircuitPreview',
    name: 'CircuitPreview',
    component: () => import('../views/svgModel/circuitPreview.vue'),
  },
];

// routes = routes.concat(mineRouter)

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

//路由守卫
router.beforeEach((to, from, next) => {
  Storage.set('token', getUrlKey('token').replace(/"/g, ''));
  Storage.set('developUrl', getUrlKey('developUrl'));
  //iframe指定路由跳转拦截
  let routerName = getUrlKey('routerName');
  if (routerName && routerName != 'undefined' && to.name != routerName) {
    next({ name: routerName });
  } else {
    next();
  }
});

export default router;
